﻿using System;
using System.Globalization;
using Cesave.DistributedServices.PermisosModule.WindowsHost.Resources;
using Cesave.DistributedServices.PermisosModule.WindowsHost.ViewModelBase;
using Cesave.DistributedServices.PermisosModule.WindowsHost.Views.Catalogs.Juntas;

namespace Cesave.DistributedServices.PermisosModule.WindowsHost.ViewModels.Catalogs.Juntas
{
	/// <summary>
	/// 
	/// </summary>
	public partial class JuntasViewModel
		: ObservableObject
	{

		#region Private properties

		/// <summary>
		/// 
		/// </summary>
		private JuntasView _juntasView;

		#endregion

		#region Constructor

		/// <summary>
		/// 
		/// </summary>
		/// <param name="juntasView"></param>
		public JuntasViewModel(JuntasView juntasView)
		{
			if (juntasView == null)
				throw new ArgumentNullException("juntasView");
			_juntasView = juntasView;
			WireUpEvents();
			InitModels();
		}

		#endregion

		#region Event methods

		/// <summary>
		/// 
		/// </summary>
		private void WireUpEvents()
		{
			PropertyChanged += JuntasViewModel_PropertyChanged;
			_juntasView.Load += LoadView;
			_juntasView.closeButton.Click += CloseView;
			_juntasView.saveButton.Click += SaveJunta;
			_juntasView.juntaBindingNavigatorSaveItem.Click += SaveJunta;
			_juntasView.bindingNavigatorDeleteItem.Click += DeleteJunta;
			_juntasView.bindingNavigatorAddNewItem.Click += AddNewJunta;
			_juntasView.newButton.Click += AddNewJunta;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void LoadView(object sender, EventArgs e)
		{
			_juntasView.Text = string.Format(
				CultureInfo.InvariantCulture,
				WindowTitles.JuntasWindowTitle
			);
		}

		private void CloseView(object sender, EventArgs e)
		{
			_juntasView.Close();
		}

		#endregion

		#region Private methods

		/// <summary>
		/// 
		/// </summary>
		private void InitModels()
		{
			LoadEstados();
		}

		/// <summary>
		/// 
		/// </summary>
		private void StartWaiting()
		{
			_juntasView.WaitingBar.StartWaiting();
		}

		/// <summary>
		/// 
		/// </summary>
		private void EndWaiting()
		{
			_juntasView.WaitingBar.EndWaiting();
		}

		/// <summary>
		/// 
		/// </summary>
		private void FocusDefaultControl()
		{
			_juntasView.ActiveControl = _juntasView.nombreUltraTextEditor;
		}

		#endregion

	}
}
